package com.eco.fanliapp.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eco.fanliapp.entity.AppUserRedReward;
import com.eco.fanliapp.entity.AppUserSearchHistory;
import com.eco.fanliapp.vo.AppUserRedRewardVo;
import com.eco.fanliapp.vo.RedFristBuyVo;
import com.eco.fanliapp.vo.RedRewardInvitationListVo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface AppUserRedRewardMapper extends BaseMapper<AppUserRedReward> {

    int deleteByPrimaryKey(Long tableId);

    @Override
    int insert(AppUserRedReward record);

    int insertSelective(AppUserRedReward record);

    AppUserRedReward selectByPrimaryKey(Long tableId);

    int updateByPrimaryKeySelective(AppUserRedReward record);

    int updateByPrimaryKey(AppUserRedReward record);

    /**
     * 查询红包
     *
     * @param status      (1,2)
     * @param type(1,2,3)
     * @return
     */
    List<AppUserRedReward> selectStatus(@Param("status") String status, @Param("type") String type);


    /**
     * 根据状态类型查询红包的总和
     *
     * @param status
     * @param type
     * @return
     */
    int selectCountByStatusType(@Param("status") int status, @Param("type") int type);


    /**
     * 修改订单状态
     *
     * @param orderId
     * @param status
     * @return
     */
    int updateAppUserRedReward(@Param("orderId") Long orderId, @Param("status") int status);

    /**
     * 定时任务用到
     *
     * @return
     */
    List<AppUserRedReward> selectAppUserRedReward(@Param("stime")Long stime, @Param("etime")Long etime);
    /**
     * 查询新人红包，首购红包
     *
     * @return
     */

    List<AppUserRedReward> selectAppUserRedRewardList(Long userId);


    /**
     * 查询红包状态为2的未领取和已领取的总数
     *
     * @return
     */
    HashMap selectHbMoney(Long userId);


    List<Map> getMoneyListHbType(Long userId);

    /**
     * 查询红包
     *
     * @return
     */
    AppUserRedReward selectGetHbMoney(@Param("userId") Long userId, @Param("tableId") Integer tableId, @Param("hbType") int hbType, @Param("hbStatus") int hbStatus);

    int updateHbStatus(AppUserRedReward appUserRedReward);

    /**
     * 通过订单id更新红包状态
     *
     * @param orderId
     * @return
     */
    int updateStatusByOrderId(Long orderId);


    /**
     * 定时清理失效的红包
     */
    int updateRedMoneyStatusSx(Long time);

    int updateHbMoneyStatus(AppUserRedReward appUserRedReward);

    /**
     * 定时修改可领取的红包为3
     */
    int updateRedMoneyStatusLq(long time);

    int updateNewRedMoneyStatusSx(long time);

    int updateRedMoneyTask(@Param("tableId") int tableId, @Param("updateTime") Long updateTime);

    int updateRedPackge(@Param("tableId") int tableId, @Param("updateTime") Long updateTime);

    List<AppUserRedReward> selectByTask(@Param("starTime")Long starTime,@Param("endTime") Long endTime);

    /**
     * 修改红包状态
     *
     * @param appUserRedReward
     * @return
     */
    int updateAppUserRedRewardExpireTime(AppUserRedReward appUserRedReward);

    List<AppUserRedReward> findRedRewardList(Long userId);

    /**
     * 获得新人，任务红包弹窗
     *
     * @param userId
     * @return
     */
    AppUserRedReward getNewRedPacket(@Param("userId") Long userId, @Param("hbType") Integer hbType, @Param("time") Long time);

    int openNewRedPacket(@Param("userId") Long userId, @Param("hbType") Integer hbType);


    HashMap<String, BigDecimal> getTotalMoney(Long userId);

    AppUserRedReward getNewRedMoneyPacket(Long userId);

    AppUserSearchHistory selectAppUserHistory(Long userId);

    Integer selectCountMoneyStatus(@Param("userId") Long userId, @Param("status") Integer status);

    AppUserRedReward selectAppUserRedRewardById(@Param("orderId") Long orderId, @Param("userId") Long userId);

    String moneySumByDate(@Param("startTime") long startTime, @Param("endTime") long endTime, @Param("companyId") Integer companyId);

    List<RedRewardInvitationListVo> findInvitationList(@Param("monthType") Integer monthType);

    List<Map> findMoneyListHbType(@Param("userId") Long userId, @Param("type") Integer type);

    Map invitationMakeMoneyByUserId(Long userId);

    List<RedRewardInvitationListVo> findInvitationFakeList(Integer type);

    void updateFakeList(@Param("id") Long userId, @Param("money") BigDecimal money);

    List<AppUserRedRewardVo> queryUserRedRewardSm();

    Integer selectStatusByIdAndType(@Param("userId") Long userId, @Param("type") int type);

    Integer totalFissionNumber(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

    Double totalRedEnvelopeForBeginners(@Param("companyId") Integer companyId, @Param("type") Integer type, @Param("flag") Integer flag);

    String totalFirstPurchaseBonusPacket(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

    Double totalSignAmount(@Param("companyId") Integer companyId,@Param("flag") Integer flag);

	int totalRedEnvelopeForBeginnersCount(@Param("companyId") Integer companyId, @Param("type") Integer type, @Param("flag") Integer flag);

	String recommendedCommission(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

    List<RedFristBuyVo> selectFristBuyDownload();

    /**
     * 邀请人数榜
     * @param month
     * @param type
     * @return
     */
    List<RedRewardInvitationListVo> invitationfansNumber(@Param("month") Integer month, @Param("type")Integer type);

    /**
     * 修改邀请人数
     * @param listVo
     */
    void updateFansVoList(RedRewardInvitationListVo listVo);
}